﻿Public Class MessageExt
    Inherits Base

    Private Sub MessageExt_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        btnAceptar.TextAlign = ContentAlignment.MiddleCenter
        btnAceptar.DialogResult = Windows.Forms.DialogResult.OK

        btnCancelar.TextAlign = ContentAlignment.MiddleCenter
        btnCancelar.DialogResult = Windows.Forms.DialogResult.Cancel

        btnReintentar.TextAlign = ContentAlignment.MiddleCenter
        btnReintentar.DialogResult = Windows.Forms.DialogResult.Retry

        btnSI.TextAlign = ContentAlignment.MiddleCenter
        btnSI.DialogResult = Windows.Forms.DialogResult.Yes

        btnNO.TextAlign = ContentAlignment.MiddleCenter
        btnNO.DialogResult = Windows.Forms.DialogResult.No

        btnAbortar.TextAlign = ContentAlignment.MiddleCenter
        btnAbortar.DialogResult = Windows.Forms.DialogResult.Abort

        btnIgnorar.TextAlign = ContentAlignment.MiddleCenter
        btnIgnorar.DialogResult = Windows.Forms.DialogResult.Ignore

    End Sub

    Private Sub setMessage(msg As String)

        Dim number As Integer = Math.Abs(msg.Length / 30)
        If number <> 0 Then
            Me.lblMessageText.Height = number * 25
        End If
        Me.lblMessageText.Text = msg

    End Sub

    Private Sub addButton(button As MessageBoxButtons)
        btnAceptar.Visible = False
        btnCancelar.Visible = False
        btnReintentar.Visible = False
        btnSI.Visible = False
        btnNO.Visible = False
        btnAbortar.Visible = False
        btnIgnorar.Visible = False
        Select Case (button)
            Case MessageBoxButtons.OK
                btnAceptar.Location = New Point(150, 131)
                btnAceptar.Visible = True
            Case MessageBoxButtons.OKCancel
                btnAceptar.Location = New Point(88, 131)
                btnAceptar.Visible = True
                btnCancelar.Location = New Point(190, 131)
                btnCancelar.Visible = True
            Case MessageBoxButtons.RetryCancel
                btnReintentar.Location = New Point(88, 131)
                btnReintentar.Visible = True
                btnCancelar.Location = New Point(190, 131)
                btnCancelar.Visible = True
            Case MessageBoxButtons.YesNo
                btnSI.Location = New Point(88, 131)
                btnSI.Visible = True
                btnNO.Location = New Point(190, 131)
                btnNO.Visible = True
            Case MessageBoxButtons.YesNoCancel
                btnSI.Location = New Point(62, 131)
                btnSI.Visible = True
                btnNO.Location = New Point(150, 131)
                btnNO.Visible = True
                btnCancelar.Location = New Point(238, 131)
                btnCancelar.Visible = True
            Case MessageBoxButtons.AbortRetryIgnore
                btnAbortar.Location = New Point(62, 131)
                btnAbortar.Visible = True
                btnReintentar.Location = New Point(150, 131)
                btnReintentar.Visible = True
                btnIgnorar.Location = New Point(238, 131)
                btnIgnorar.Visible = True
        End Select

    End Sub

    Private Sub addIconImage(icon As MessageBoxIcon)

    End Sub


    Public Overloads Shared Function Show(text As String) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = Application.ProductName
        frmMessage.addIconImage(MessageBoxIcon.Information)
        frmMessage.addButton(MessageBoxButtons.OK)
        Return frmMessage.ShowDialog()
    End Function

    Public Overloads Shared Function Show(text As String, caption As String) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = caption
        frmMessage.addIconImage(MessageBoxIcon.Information)
        frmMessage.addButton(MessageBoxButtons.OK)
        Return frmMessage.ShowDialog()
    End Function

    Public Overloads Shared Function Show(text As String, caption As String, buttons As MessageBoxButtons) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = caption
        frmMessage.addIconImage(MessageBoxIcon.Information)
        frmMessage.addButton(buttons)
        Return frmMessage.ShowDialog()
    End Function

    Public Overloads Shared Function Show(text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = caption
        frmMessage.addIconImage(icon)
        frmMessage.addButton(buttons)
        Return frmMessage.ShowDialog()
    End Function

    Public Overloads Shared Function Show(text As String, buttons As MessageBoxButtons, icon As MessageBoxIcon) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = Application.ProductName
        frmMessage.addIconImage(icon)
        frmMessage.addButton(buttons)
        Return frmMessage.ShowDialog()
    End Function

    Public Overloads Shared Function Show(text As String, icon As MessageBoxIcon) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = Application.ProductName
        frmMessage.addIconImage(icon)
        frmMessage.addButton(MessageBoxButtons.OK)
        Return frmMessage.ShowDialog()
    End Function

    Public Overloads Shared Function Show(text As String, buttons As MessageBoxButtons) As DialogResult
        Dim frmMessage As New MessageExt()
        frmMessage.setMessage(text)
        frmMessage.Text = Application.ProductName
        frmMessage.addIconImage(MessageBoxIcon.Information)
        frmMessage.addButton(buttons)
        Return frmMessage.ShowDialog()

    End Function
End Class